package com.wikidot.designpatterns.memento;

import java.util.ArrayList;
import java.util.List;

/**
 * Caretaker part. Here states are archived and then retrieved to be restored.
 */
public class HistoryLog {
	/**
	 * Storage of the states.
	 */
	private List<LogRecord> history = new ArrayList<LogRecord>();

	/**
	 * Saves state into archive.
	 * 
	 * @param record
	 *            State to be saved.
	 */
	public void saveRecord(LogRecord record) {
		this.history.add(record);
	}

	/**
	 * Retrieves gived state from the archive.
	 * 
	 * @param index
	 *            State to be retrieved.
	 * @return Retrieved state.
	 */
	public LogRecord getRecord(int index) {
		return history.get(index);
	}

	/**
	 * This is only informative method that lists all archived states.
	 */
	public void listRecords() {
		System.out.println("Saved checkpoints: ");
		for (int i = 0; i < history.size(); i++) {
			System.out.println(i + 1 + ": " + history.get(i));
		}
	}
}
